﻿//=================================================== 
// 
// 文件名 :SmsHelper 
// 简介: 
// 作者： 小钟
// 日期：2009-7-10 10:42:01 
// 
//====================================================

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GCELibrary.Current.SmsMessage
{
    /// <summary>
    ///  短信辅助类
    /// </summary>
    public class SmsHelper
    {
        public static bool IsConnect { get { return SmsConfig.SmsAdpter.IsConnect; } }
        /// <summary>
        ///  发送短信（暂时未分段发送）
        /// </summary>
        /// <param name="msgContent">短信信息</param>
        /// <param name="receivNum">短信号码</param>
        /// <returns></returns>
        public static bool SendMsg(string msgContent, string receivNum)
        {
            bool IsSendSuccess = false;

            // 验证手机号码
            bool isUsefulPhone = System.Text.RegularExpressions.Regex.IsMatch(receivNum, SmsConfig.NumberUsefulValidator);

            bool connSuccess = IsConnect ? true : SmsConfig.SmsAdpter.Connect();

            if (!msgContent.Trim().Equals(string.Empty) && isUsefulPhone && connSuccess) // 保证短信不为空 & 号码正确 & 连接成功
            {
                
                if (SmsConfig.NeedAddDate) // 是否需要追加日期
                {
                    msgContent += DateTime.Now.ToShortDateString();
                }
                IsSendSuccess = SmsConfig.SmsAdpter.SendMsg(msgContent, receivNum);
            }
            return IsSendSuccess;
        }
        /// <summary>
        ///  获取剩余短信数量
        /// </summary>
        /// <returns></returns>
        public static int GetCount()
        {
            return SmsConfig.SmsAdpter.GetCount();
        }
        /// <summary>
        ///  连接
        /// </summary>
        /// <returns></returns>
        public static bool Connect()
        {
            return SmsConfig.SmsAdpter.Connect();
        }
        /// <summary>
        ///  断开链接
        /// </summary>
        public static void Disonnect()
        {
            SmsConfig.SmsAdpter.Disonnect();
        }
    }

}
